package com.hdjk.view.callback;

import com.hdjk.view.entity.FundEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.math.BigDecimal;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetWalletFundCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONArray array = (JSONArray) msg.getData();
        if (array != null && array.length() > 0) {
            JSONObject object = array.getJSONObject(0);
            if (object != null) {
                FundEntity entity = new FundEntity();
                if (!object.isNull("fundCode")) {
                    entity.setFundCode(object.getString("fundCode"));
                }
                if (!object.isNull("fundName")) {
                    entity.setFundName(object.getString("fundName"));
                }
                if (!object.isNull("fundFullName")) {
                    entity.setFundFullName(object.getString("fundFullName"));
                }
                if (!object.isNull("fundType")) {
                    entity.setFundType(object.getString("fundType"));
                }
                if (!object.isNull("fundStatus")) {
                    entity.setFundStatus(object.getString("fundStatus"));
                }
                if (!object.isNull("nav")) {
                    double l = object.getDouble("nav");
                    BigDecimal b = new BigDecimal(l);
                    entity.setNav(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("fundHouse")) {
                    entity.setFundHouse(object.getString("fundHouse"));
                }
                if (!object.isNull("fundHouseCode")) {
                    entity.setFundHouseCode(object.getString("fundHouseCode"));
                }
                if (!object.isNull("accumulateNav")) {
                    double l = object.getDouble("accumulateNav");
                    BigDecimal b = new BigDecimal(l);
                    entity.setAccumulateNav(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("day1Performance")) {
                    double l = object.getDouble("day1Performance");
                    BigDecimal b = new BigDecimal(l);
                    entity.setDay1Performance(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("navDate")) {
                    entity.setNavDate(object.getString("navDate"));
                }
                if (!object.isNull("earningsPer10000")) {
                    double l = object.getDouble("earningsPer10000");
                    BigDecimal b = new BigDecimal(l);
                    entity.setEarningsPer10000(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("sevenDaysAnnualizedYield")) {
                    double l = object.getDouble("sevenDaysAnnualizedYield");
                    BigDecimal b = new BigDecimal(l);
                    entity.setSevenDaysAnnualizedYield(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("isBuyEnable")) {
                    entity.setIsBuyEnable(object.getString("isBuyEnable"));
                }
                if (!object.isNull("isQDII")) {
                    entity.setIsQDII(object.getString("isQDII"));
                }
                if (!object.isNull("isMMFund")) {
                    entity.setIsMMFund(object.getString("isMMFund"));
                }
                if (!object.isNull("isRecommended")) {
                    entity.setIsRecommended(object.getString("isRecommended"));
                }
                if (!object.isNull("month1")) {
                    entity.setMonth1(object.getString("month1"));
                }
                if (!object.isNull("month3")) {
                    entity.setMonth3(object.getString("month3"));
                }
                if (!object.isNull("month6")) {
                    entity.setMonth6(object.getString("month6"));
                }
                if (!object.isNull("year1")) {
                    entity.setYear1(object.getString("year1"));
                }
                if (!object.isNull("year3")) {
                    entity.setYear3(object.getString("year3"));
                }
                if (!object.isNull("year5")) {
                    entity.setYear5(object.getString("year5"));
                }
                if (!object.isNull("sinceLaunch")) {
                    entity.setSinceLaunch(object.getString("sinceLaunch"));
                }
                if (!object.isNull("specializeSector")) {
                    entity.setSpecializeSector(object.getString("specializeSector"));
                }
                if (!object.isNull("geographicalSector")) {
                    entity.setGeographicalSector(object.getString("geographicalSector"));
                }
                if (!object.isNull("riskRate")) {
                    entity.setRiskRate(object.getString("riskRate"));
                }
                if (!object.isNull("fundSize")) {
                    entity.setFundSize(object.getString("fundSize"));
                }
                if (!object.isNull("chargeMode")) {
                    entity.setChargeMode(object.getString("chargeMode"));
                }
                if (!object.isNull("currency")) {
                    entity.setCurrency(object.getString("currency"));
                }
                if (!object.isNull("defaultDividendInstruction")) {
                    entity.setDefaultDividendInstruction(object.getString("defaultDividendInstruction"));
                }
                if (!object.isNull("dividendUpdateEnable")) {
                    entity.setDividendUpdateEnable(object.getString("dividendUpdateEnable"));
                }
                if (!object.isNull("fundCustodian")) {
                    entity.setFundCustodian(object.getString("fundCustodian"));
                }
                if (!object.isNull("launchDate")) {
                    entity.setLaunchDate(object.getString("launchDate"));
                }
                if (!object.isNull("launchSize")) {
                    entity.setLaunchSize(object.getString("launchSize"));
                }
                if (!object.isNull("launchPrice")) {
                    entity.setLaunchPrice(object.getString("launchPrice"));
                }
                if (!object.isNull("fundSizeDate")) {
                    entity.setFundSizeDate(object.getString("fundSizeDate"));
                }
                if (!object.isNull("managementFee")) {
                    double l = object.getDouble("managementFee");
                    BigDecimal b = new BigDecimal(l);
                    entity.setManagementFee(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("custodianFee")) {
                    double l = object.getDouble("custodianFee");
                    BigDecimal b = new BigDecimal(l);
                    entity.setCustodianFee(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("investmentObjective")) {
                    entity.setInvestmentObjective(object.getString("investmentObjective"));
                }
                if (!object.isNull("investmentScope")) {
                    entity.setInvestmentScope(object.getString("investmentScope"));
                }
                if (!object.isNull("investmentStrategy")) {
                    entity.setInvestmentStrategy(object.getString("investmentStrategy"));
                }
                if (!object.isNull("riskDisclosure")) {
                    entity.setRiskDisclosure(object.getString("riskDisclosure"));
                }
                if (!object.isNull("ipoStartDate")) {
                    entity.setIpoStartDate(object.getString("ipoStartDate"));
                }
                if (!object.isNull("ipoEndDate")) {
                    entity.setIpoEndDate(object.getString("ipoEndDate"));
                }
                if (!object.isNull("isRspEnable")) {
                    entity.setIsRspEnable(object.getString("isRspEnable"));
                }
                if (!object.isNull("isSellEnable")) {
                    entity.setIsSellEnable(object.getString("isSellEnable"));
                }
                if (!object.isNull("isSwitchEnable")) {
                    entity.setIsSwitchEnable(object.getString("isSwitchEnable"));
                }
                if (!object.isNull("maxBuyAmount")) {
                    double l = object.getDouble("maxBuyAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMaxBuyAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("maxIpoAmount")) {
                    double l = object.getDouble("maxIpoAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMaxIpoAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("maxRspAmount")) {
                    double l = object.getDouble("maxRspAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMaxRspAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minInitialBuyAmount")) {
                    double l = object.getDouble("minInitialBuyAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinInitialBuyAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minInitialIpoAmount")) {
                    double l = object.getDouble("minInitialIpoAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinInitialIpoAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minSubseqBuyAmout")) {
                    double l = object.getDouble("minSubseqBuyAmout");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinSubseqBuyAmout(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minSubseqIpoAmout")) {
                    double l = object.getDouble("minSubseqIpoAmout");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinSubseqIpoAmout(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minRspAmount")) {
                    double l = object.getDouble("minRspAmount");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinRspAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minRedemptionUnit")) {
                    double l = object.getDouble("minRedemptionUnit");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinRedemptionUnit(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("minRetainUnit")) {
                    double l = object.getDouble("minRetainUnit");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMinRetainUnit(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("buyConfirmLag")) {
                    entity.setBuyConfirmLag(object.getString("buyConfirmLag"));
                }
                if (!object.isNull("redemptionSettleLag")) {
                    entity.setRedemptionSettleLag(object.getString("redemptionSettleLag"));
                }
                msg.setData(entity);
            }
        }
        return msg;
    }
}
